// pages/component/homes/balancedetail/balancedetail.js
var that;
var dataManager = require('../../../../utils/dataManager.js');
var GlobalData = require('../../../../utils/GlobalData.js');
var Util = require('../../../../utils/util.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    balanceArr: [],
    page: 20,
    arrlength: 0,
    haveData: false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    dataManager.removeBtnObserver("balancedetail")
    if (GlobalData.BalanceDetail) {
      this.onComplete();
    } else {
      dataManager.rigisterObserver("balancedetail", this.onComplete, this);
      dataManager.getBalanceDetail(GlobalData.BalanceDetailother["index"], GlobalData.BalanceDetailother["size"], GlobalData.BalanceDetailother["add"]);
    }


  },
  onComplete: function () {
    this.setData({
      balanceArr: GlobalData.BalanceDetail
    })

    if (GlobalData.BalanceDetail.length == this.data.arrlength)
      return;
    if (GlobalData.BalanceDetail)
      var ar = GlobalData.BalanceDetail;
    for (let i = 0; i < ar.length; i++) {
      let amount = parseInt(ar[i].amount);
      let str = "" + ar[i].amount;
      if (amount > 0 && str.indexOf("+") < 0)
        ar[i].amount = "+" + ar[i].amount;
      ar[i].createtime = ar[i].createtime.replace('T', ' ');
      if (ar[i].remark == null) {
        ar[i].remark = " "
      }
      if (ar[i].remark.indexOf("</br>") > -1) {
        ar[i].remark = ar[i].remark.replace("</br>", "");
      }
    }
    this.setData({
      balanceArr: ar
    })

    this.data.arrlength = ar.length;
    /**判断是否有数据 */
    if (ar.length == 0)
      this.data.haveData = true;

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    GlobalData.BalanceDetailother["index"] = GlobalData.BalanceDetailother["index"] + 1;
    dataManager.rigisterObserver("balancedetail", this.onComplete, this);
    dataManager.getBalanceDetail(GlobalData.BalanceDetailother["index"], GlobalData.BalanceDetailother["size"], true);

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})